package com.huawei.appgallery.assistantdock.base.service;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.huawei.appgallery.assistantdock.base.service.base.dispatch.GameServiceDispatcher;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.gamebox.plugin.gameservice.service.RequestInfo;
import java.lang.reflect.Method;
import o.bga;
import o.diu;
import o.Logger;
import o.fad;

public abstract class BaseGameServiceDispatcher implements GameServiceDispatcher {
    private static final String TAG = "BaseGameServiceDispatcher";
    protected fad mCallback;
    protected Context mContext;
    protected GameInfo mGameInfo;
    protected String mReqId;

    public void dispatch(Context context, @NonNull RequestInfo requestInfo, fad o_fad) {
        if (this.mGameInfo == null) {
            this.mGameInfo = new GameInfo();
        }
        this.mGameInfo.setSdkVersionCode(requestInfo.ˋ());
        this.mGameInfo.setSdkVersionName(requestInfo.ˏ());
        this.mGameInfo.setCpId(requestInfo.ˊ());
        this.mGameInfo.setPackageName(requestInfo.ॱॱ());
        this.mGameInfo.setAppId(requestInfo.ˎ());
        this.mCallback = o_fad;
        this.mContext = context;
        this.mReqId = requestInfo.ॱ();
        if (Logger.ˎ()) {
            Logger.ˏ(TAG, "dispatch aidl method, mReqId:" + this.mReqId);
        }
        try {
            Method declaredMethod = getClass().getDeclaredMethod(this.mReqId, new Class[0]);
            if (!declaredMethod.isAnnotationPresent(PermissionGuard.class)) {
                declaredMethod.invoke(this, new Object[0]);
            } else if (checkBuoyPermission(requestInfo, o_fad)) {
                declaredMethod.invoke(this, new Object[0]);
            }
        } catch (Throwable e) {
            Logger.ˋ(TAG, "dispatch error", e);
        }
    }

    public void destroy() {
    }

    public void unbind() {
    }

    public void onContinue() {
        if (Logger.ˎ()) {
            Logger.ˏ(TAG, "continue aidl method, mReqId:" + this.mReqId);
        }
        try {
            getClass().getDeclaredMethod(this.mReqId, new Class[0]).invoke(this, new Object[0]);
        } catch (Throwable e) {
            Logger.ˋ(TAG, "dispatch error", e);
        }
    }

    private boolean checkBuoyPermission(@NonNull RequestInfo requestInfo, fad o_fad) {
        if (diu.ˊ().ˎ()) {
            return true;
        }
        Intent intent = new Intent(this.mContext, GameServicePermissionActivity.class);
        Bundle bundle = new Bundle();
        bundle.putParcelable("REQUEST_INFO_KEY", requestInfo);
        intent.putExtras(bundle);
        bga.ॱ().ˎ(this.mGameInfo, GameServicePermissionActivity.class, intent, o_fad);
        return false;
    }
}
